package com.thememaker.lockstyle;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXListView;
import com.jfoenix.controls.JFXTreeView;
import com.jfoenix.svg.SVGGlyph;
import com.thememake.Constants;
import com.thememake.common.base.Strings;
import com.thememake.entity.ThemeFileInfo;
import com.thememake.ninepatch.NinePatchUtils;
import com.thememake.service.PutProductScheduledService;
import com.thememake.ui.CtsFileChooser;
import com.thememake.ui.Toast;
import com.thememake.ui.dialog.ProgressDialog;
import com.thememake.ui.dialog.SBTFxDialog;
import com.thememake.util.FileUtils;
import com.thememake.util.image.ImageUtils;
import com.thememake.util.image.changesize.ImageChangeSizeUtils;
import com.thememake.util.xml.fontcolor.ReadXmlUtils;
import com.thememaker.lockstyle.bean.Lockscreen;
import com.thememaker.lockstyle.bean.Var;
import com.thememaker.lockstyle.bean.ui.*;
import com.thememaker.lockstyle.bean.ui.Image;
import com.thememaker.lockstyle.bean.ui.Slider;
import com.thememaker.lockstyle.control.*;
import com.thememaker.lockstyle.parsii.ExpressionUtils;
import com.thememaker.lockstyle.parsii.LockscreenViewPaesiiUtils;
import com.thememaker.util.*;
import javafx.animation.ParallelTransition;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.scene.transform.Rotate;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.w3c.dom.Document;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.List;
import java.util.function.Consumer;

import static com.thememaker.lockstyle.LockstyleMainController.buttonColor;

/**
 * Created by jiajun.jiang on 2018/2/27.
 */
public class LockstyleShowUtils {
    private ThemeFileInfo themeFileInfo;
    private Path lockscreenPath;
    private AnchorPane centerAnchorPane;
    private VBox leftAnchorPane, leftFileAnchorPane;
    private Lockscreen lockscreen;
    private Document document;
    private ExpressionUtils expressionUtils;
    private String lockscreenPathString;
    private float rate = 480f / 1080f;
    private List<ParallelTransition> parallelTransitionList;

    private boolean isEdit = true;
    private Stage stage;
    private LockstyleMainController lockstyleMainController;
    private LockStyleCenterEditUtils lockStyleCenterEditUtils;
    private LockStyleCenterLeftEditUtils lockStyleCenterLeftEditUtils;
    private LockstyleCenterBottomArea lockstyleCenterBottomArea;
    private LockstyleControlUtils lockstyleControlUtils;
    private LockstyleShowRightEventControl lockstyleShowRightEventControl;

    private LockCheckBoxTreeItem<BaseView> treeItem;

    private LockstyleBottomUtils lockstyleBottomUtils;

    private SplitPane splitPane;
    private int count = 0;

    private Map<String, Node> rightViewNodeMap;

    public void setExpressionUtils(ExpressionUtils expressionUtils) {
        this.expressionUtils = expressionUtils;
    }

    public Document getDocument() {
        return document;
    }

    public Path getLockscreenPath() {
        return lockscreenPath;
    }

    public Lockscreen getLockscreen() {
        return lockscreen;
    }

    public void setLockscreen(Lockscreen lockscreen) {
        this.lockscreen = lockscreen;
    }

    public float getRate() {
        return rate;
    }

    public void setRate(float rate) {
        this.rate = rate;
    }

    public void setLockstyleMainController(LockstyleMainController lockstyleMainController) {
        this.lockstyleMainController = lockstyleMainController;
    }

    public void setLockstyleControlUtils(LockstyleControlUtils lockstyleControlUtils) {
        this.lockstyleControlUtils = lockstyleControlUtils;
    }

    public void setLockStyleCenterLeftEditUtils(LockStyleCenterLeftEditUtils lockStyleCenterLeftEditUtils) {
        this.lockStyleCenterLeftEditUtils = lockStyleCenterLeftEditUtils;
    }

    public void setLockstyleCenterController(LockStyleCenterEditUtils lockStyleCenterEditUtils) {
        this.lockStyleCenterEditUtils = lockStyleCenterEditUtils;
    }

    public void setLockstyleCenterBottomArea(LockstyleCenterBottomArea lockstyleCenterBottomArea) {
        this.lockstyleCenterBottomArea = lockstyleCenterBottomArea;
    }

    public void setLockstyleBottomUtils(LockstyleBottomUtils lockstyleBottomUtils) {
        this.lockstyleBottomUtils = lockstyleBottomUtils;
    }

    public void setLockstyleShowRightEventControl(ExpressionUtils expressionUtils, Stage stage, LockStyleCenterEditUtils lockStyleCenterEditUtils, LockStyleCenterLeftEditUtils lockStyleCenterLeftEditUtils, Path lockscreenPath) {
        this.lockstyleShowRightEventControl = new LockstyleShowRightEventControl(expressionUtils, stage, this, lockStyleCenterEditUtils, lockStyleCenterLeftEditUtils, lockscreenPath);
    }

    public boolean isEdit() {
        return isEdit;
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    public LockstyleShowUtils(SplitPane splitPane, VBox leftAnchorPane, VBox leftFileAnchorPane, AnchorPane centerAnchorPane, Path lockscreenPath, ThemeFileInfo themeFileInfo, Stage stage) {
        this.stage = stage;
        this.lockscreenPath = lockscreenPath;
        this.leftAnchorPane = leftAnchorPane;
        this.leftFileAnchorPane = leftFileAnchorPane;
        this.centerAnchorPane = centerAnchorPane;
        this.themeFileInfo = themeFileInfo;
        this.splitPane = splitPane;
        // 启动自动保存
        AutoSaveUtils.getInstance(themeFileInfo).startAutoSave(this);
    }

    public void startAnimation() {
        if (parallelTransitionList != null && parallelTransitionList.size() > 0) {
            for (ParallelTransition parallelTransition : parallelTransitionList) {
                parallelTransition.play();
            }
        }
    }

    public void stopAnimation() {
        if (parallelTransitionList != null && parallelTransitionList.size() > 0) {
            for (ParallelTransition parallelTransition : parallelTransitionList) {
                parallelTransition.play();
                parallelTransition.pause();
            }
        }
    }

    public void save() {
        ProgressDialog progressFrom = new ProgressDialog(new Task<Void>() {
            @Override
            protected Void call() {
                try {
                    System.err.println("lockscreen >>> " + JSON.toJSONString(lockscreen.getLockScreenViewMap()));
                    LockstylePaserUtils.saveLockScreenXml(themeFileInfo, document, lockscreen, Paths.get(lockscreenPath.toString(), "manifest.xml").toFile());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        }, stage, "正在保存，请稍等...");
        progressFrom.showProgressBar(() -> {
            Toast.makeText(stage, "保存成功", 1000);
            showLockscreen();
        });
    }
    public void save2(){
        LockstylePaserUtils.saveLockScreenXml(themeFileInfo, document, lockscreen, Paths.get(lockscreenPath.toString(), "manifest.xml").toFile());
    }

    public void savePreview(javafx.scene.image.Image image) {
        File previewFile = new File(lockscreenPath.getParent().toString(), "lockscreenPreview.jpg");
        File tempFile = new File(lockscreenPath.getParent().toString(), "lockscreenPreview_temp.png");
        try {
            ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", tempFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (tempFile.exists()) {
            ImageUtils.convertImage(tempFile, previewFile);
        }
        if (themeFileInfo.getThemeType().equals(Constants.VIVO)) {
            if (previewFile.exists()) {
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "3.0", "480", "preview_lockscreen_0.jpg"), "480");
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "3.0", "720", "preview_lockscreen_0.jpg"), "720");
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "3.0", "1080", "preview_lockscreen_0.jpg"), "1080");
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "3.0", "1440", "preview_lockscreen_0.jpg"), "1440");

                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "2.5", "480", "preview_lockscreen.jpg"), "480");
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "2.5", "720", "preview_lockscreen.jpg"), "720");
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "2.5", "1080", "preview_lockscreen.jpg"), "1080");
                ImageChangeDensityUtil.doScale480Image(previewFile.toPath(),
                        Paths.get(themeFileInfo.getOutputDir().getPath(), "preview", "2.5", "1440", "preview_lockscreen.jpg"), "1440");

            }
        } else if (themeFileInfo.getThemeType().equals(Constants.OPPO)) {
            try {
                Path previewPath = Paths.get(themeFileInfo.getOutputDir().toString(), "picture", "res", "drawable-xxhdpi", "preview_lock.png");
                Path thumbnailPath = Paths.get(themeFileInfo.getOutputDir().toString(), "picture", "res", "drawable-xxhdpi", "thumbnail.png");
                ImageChangeSizeUtils.ImageChangeSize(tempFile.getPath(), previewPath.toString(), 1080, 1920);
                ImageChangeSizeUtils.ImageChangeSize(tempFile.getPath(), thumbnailPath.toString(), 328, 583);
                new NinePatchUtils().zooPNG(previewPath.toString(), previewPath.toString());
                new NinePatchUtils().zooPNG(thumbnailPath.toString(), thumbnailPath.toString());
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (themeFileInfo.getThemeType().equals(Constants.OS360) || themeFileInfo.getThemeType().equals("os360")) {
            if (previewFile.exists()) {
                Path previewPath = Paths.get(themeFileInfo.getOutputDir().toString(), "res", "preview01.jpg");
                Path minPreviewPath = Paths.get(themeFileInfo.getOutputDir().toString(), "preview", "min_preview.jpg");
                try {
                    ImageChangeSizeUtils.ImageChangeSize(previewFile.getPath(), previewPath.toString(), 1080, 1920);
                    ImageChangeSizeUtils.ImageChangeSize(previewFile.getPath(), minPreviewPath.toString(), 360, 640);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        PutProductScheduledService putProductScheduledService = new PutProductScheduledService(themeFileInfo, previewFile, null);
        putProductScheduledService.setOnSucceeded(value -> {
            System.err.println("putProductScheduledService   setOnSucceeded");
            putProductScheduledService.cancel();
        });
        putProductScheduledService.start();
        try {
            Files.delete(tempFile.toPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void showLockscreen() {
        System.err.println("expressionUtils.getScreen_height() >>> " + expressionUtils.getScreen_height());
        if (parallelTransitionList != null) {
            parallelTransitionList.clear();
        } else {
            parallelTransitionList = new ArrayList<>();
        }
        if (treeItem == null) {
            treeItem = new LockCheckBoxTreeItem<>();
            treeItem.setSelected(true);
            treeItem.setValue("lockscreen");
        }
        treeItem.getChildren().clear();
        centerAnchorPane.getChildren().clear();
        rightViewNodeMap = new HashMap<>();
        lockstyleControlUtils.clear();
        ProgressDialog progressFrom = new ProgressDialog(new Task<Void>() {
            @Override
            protected Void call() {
                Path xmlPath = Paths.get(lockscreenPath.toString(), "manifest.xml");
                try {
                    if (themeFileInfo.getThemeType().equals(Constants.OPPO)) {
                        switch ((int) expressionUtils.getScreen_height()) {
                            case 2160:
                                xmlPath = Paths.get(lockscreenPath.toString(), "2x1", "manifest.xml");
                                break;
                            case 2280:
                                xmlPath = Paths.get(lockscreenPath.toString(), "19x9", "manifest.xml");
                                break;
                            case 2340:
                                xmlPath = Paths.get(lockscreenPath.toString(), "13x6", "manifest.xml");
                                break;
                            default:
                                xmlPath = Paths.get(lockscreenPath.toString(), "manifest.xml");
                                break;
                        }
                    }
                    if (!Files.exists(xmlPath)) {
                        xmlPath = Paths.get(lockscreenPath.toString(), "manifest.xml");
                        Platform.runLater(() -> {
                            Toast.makeText(stage, (int) expressionUtils.getScreen_height() + "分辨率还未适配!", 1000);
                        });
                    }
                    document = ReadXmlUtils.loadXml(xmlPath.toString());
                    lockscreenPathString = lockscreenPath.toString();
                    lockscreen = LockstylePaserUtils.paserLockScreenXml(document);

                    LinkedHashMap<String, BaseView> map = lockscreen.getLockScreenViewMap();
                    parseLinkedView(map);

                } catch (Exception e) {
                    e.printStackTrace();

                }
                return null;
            }
        }, stage, "正在预览锁屏，请稍等...");
        progressFrom.showProgressBar(() -> {
            if (VipControllerUtils.getInstance(themeFileInfo).canUseLockscreenPsd()) {
                Platform.runLater(() -> {
                    if(lockscreen==null || lockscreen.getLockScreenViewMap().size()==0){
                        SBTFxDialog.showMessageDialog(null, "锁屏文件已损坏，请检查锁屏文件！", "温馨提示", () -> {
                        }, () -> { });
                    }
                    parseTreeView(lockscreen.getLockScreenViewMap(), false, null, null);
                    treeItem.setExpanded(true);
                    treeItem.setTag(lockscreen);
                    JFXTreeView checkTreeView = new JFXTreeView<>(treeItem);
                    checkTreeView.setId("scroll-pane");
                    checkTreeView.setPrefWidth(250);
                    checkTreeView.setPrefHeight(1000);
                    checkTreeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
                    checkTreeView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
                        LockCheckBoxTreeItem<BaseView> currentSelectItem = (LockCheckBoxTreeItem<BaseView>) newValue;
                        lockStyleCenterLeftEditUtils.updateCenterTextInfo(currentSelectItem.getTag(), expressionUtils, this);
                        lockStyleCenterEditUtils.updateRightImageInfo(currentSelectItem.getTag(), lockscreenPath, this);
                    });
                    if (leftAnchorPane.getChildren() != null && leftAnchorPane.getChildren().size() > 0) {
                        leftAnchorPane.getChildren().remove(0, leftAnchorPane.getChildren().size());
                    }
                    if (LayoutComponentUtils.patternID == 1) {
                        leftModelSwitch(parseListView(lockscreen.getLockScreenViewMap()), leftAnchorPane);
                    } else if (LayoutComponentUtils.patternID == 2) {
                        leftModelSwitch(checkTreeView, leftAnchorPane);
                        lockStyleCenterLeftEditUtils.updateCenterTextInfo(lockscreen, expressionUtils, this);
                        lockStyleCenterEditUtils.updateRightImageInfo(lockscreen, lockscreenPath, this);
                    }
                    LockstyleLeftFileTree lockstyleLeftFileTree = new LockstyleLeftFileTree(stage, leftFileAnchorPane, lockscreenPath, this);
                    leftFileAnchorPane.getChildren().addAll(lockstyleLeftFileTree.addFileTree());
                });
            }
        });
    }

    private void parseLinkedView(LinkedHashMap<String, BaseView> map) {
        Platform.runLater(() -> {
            centerAnchorPane.getChildren().clear();
            rightViewNodeMap.clear();
            map.keySet().forEach(name -> {
                BaseView baseView = map.get(name);
//                System.out.println("name测试------------------->>>>>>>" + baseView.getName());
                Node node = parseLockscreenView(baseView);
                rightViewNodeMap.put(name, node);
                if (node != null) {
                    centerAnchorPane.getChildren().add(node);
                }
            });
            if (themeFileInfo.getThemeType().equals(Constants.OPPO)) {
                Path path = Paths.get(FileUtils.getResFileOfThemeModel(Constants.OPPO, "default-preview").getPath(), (int) expressionUtils.getScreen_height() + ".png");
                if (Files.exists(path)) {
                    centerAnchorPane.getChildren().add(initImageView(null, 0, 0, path.toString(), false));
                }
            }else if (themeFileInfo.getThemeType().equals(Constants.VIVO)){
                BaseView baseView = map.entrySet().stream()
                        .filter(stringBaseViewEntry -> "bg".equals(stringBaseViewEntry.getValue().getName()))
                        .findFirst().map(Map.Entry::getValue).orElse(null);
                Path bgPath = Optional.ofNullable(baseView).flatMap(baseView1 -> {
                        return Optional.ofNullable(LockscreenViewPaesiiUtils.getInstance(expressionUtils).paesiiImagePath((Image)baseView1, lockscreenPath.toString()));
                    }).orElse(null);
                centerAnchorPane.getChildren().add(new StatusBarShowUtils(themeFileInfo, 1080 * rate).getLauncherStatusBarView(Optional.ofNullable(bgPath).map(Path::toString).orElse(null)));
            }
        });
    }

    private AnchorPane parseButtonView(com.thememaker.lockstyle.bean.ui.Button baseView, Button button) {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.getChildren().addAll(button);
        if (baseView.getNormal().getImage() != null) {
            for (int i = 0; i < baseView.getNormal().getImage().size(); i++) {
                anchorPane.getChildren().addAll(parseButtonViewImage(baseView.getNormal().getImage().get(i)));
            }
            return anchorPane;
        } else {
            return anchorPane;
        }
    }

    private Button parseButtonViewImage(com.thememaker.lockstyle.bean.ui.Image image) {
        Button imgBtn = new Button();
        imgBtn.setStyle("-fx-border-color: transparent;-fx-background-color: transparent;");
        Path path = LockscreenViewPaesiiUtils.getInstance(expressionUtils).paesiiImagePath(image, lockscreenPathString);
        ImageView imageView = initImageView(imgBtn, expressionUtils.parseExpr(image.getX()), expressionUtils.parseExpr(image.getY()), path == null ? null : path.toString(), image.getFitFX());
        imgBtn.setGraphic(imageView);
        lockstyleShowRightEventControl.initButtonEvent(image, imgBtn, null);
        return imgBtn;
    }

    private AnchorPane parseGroupView(Group group) {
        AnchorPane anchorPane = new AnchorPane();
        if (group.getVisibilityFX() != null) {
            anchorPane.setVisible(group.getVisibilityFX());
        }
        if (group.getX() != null && group.getY() != null) {
            if (group.getX().contains("#unlocker.move_x") || group.getY().contains("#unlocker.move_y")) {
                group.setUnlockMoveFX(true);
            }
        } else {
            group.setX("0");
            group.setY("0");
        }
//      鼠标穿透，自身不响应
//      anchorPane.setMouseTransparent(true);
        if (!Strings.isNullOrEmpty(group.getW())) {
            double width = expressionUtils.parseExpr(group.getW()) * rate;
            anchorPane.setPrefWidth(width);
            anchorPane.setMinWidth(width);
            anchorPane.setMaxWidth(width);
        }
        if (!Strings.isNullOrEmpty(group.getH())) {
            double height = expressionUtils.parseExpr(group.getH()) * rate;
            anchorPane.setPrefHeight(height);
            anchorPane.setMinHeight(height);
            anchorPane.setMaxHeight(height);
        }
        if (!Strings.isNullOrEmpty(group.getX())) {
            anchorPane.setLayoutX(expressionUtils.parseExpr(group.getX()) * rate);
        }
        if (!Strings.isNullOrEmpty(group.getY())) {
            anchorPane.setLayoutY(expressionUtils.parseExpr(group.getY()) * rate);
        }

        if (!Strings.isNullOrEmpty(group.getAlpha())) {
            anchorPane.setStyle("-fx-opacity:" + expressionUtils.parseExpr(group.getAlpha()) / 255 + ";");
        }
        if (!Strings.isNullOrEmpty(group.getVisibility())) {
            if (expressionUtils.parseExpr(group.getVisibility()) >= 1) {
                anchorPane.setVisible(true);
            } else {
                anchorPane.setVisible(false);
            }
        }
        Platform.runLater(() -> {
            group.getGroupViewMap().keySet().forEach(name -> {
                BaseView baseView = group.getGroupViewMap().get(name);
                Node node = parseLockscreenView(baseView);
                if (node != null) {
                    rightViewNodeMap.put(name, node);
                    anchorPane.getChildren().add(node);
                }
            });
        });
        return anchorPane;
    }

    private LinkedHashMap<String, BaseView> groupMap = new LinkedHashMap<>();

    private void parseTreeView(LinkedHashMap<String, BaseView> map, boolean isGroup, String name1, BaseView baseView1) {
        LockCheckBoxTreeItem<BaseView> checkBoxTreeItem = new LockCheckBoxTreeItem<>();
        checkBoxTreeItem.setExpanded(true);
        checkBoxTreeItem.setSelected(true);
        if (name1 != null) {
            checkBoxTreeItem.setValue(baseView1.getName() != null ? baseView1.getName() : name1.replace("lockscreen_", ""));
            checkBoxTreeItem.setMapName(name1);
            checkBoxTreeItem.setTag(baseView1);
            checkBoxTreeItem.setSelected(baseView1.getVisibility() == null || expressionUtils.parseExpr(baseView1.getVisibility()) > 0.0d);
        } else {
            name1 = "lockscreen_";
        }
        String groupName = name1;
        map.keySet().forEach(name -> {
            BaseView baseView = map.get(name);
            if (baseView instanceof Group) {
                System.err.println("name >>> " + name);
                parseTreeView(((Group) baseView).getGroupViewMap(), true, name, baseView);
            } else {
                System.err.println("name-- >>> " + name);
                LockCheckBoxTreeItem<BaseView> checkBoxTreeItem11 = new LockCheckBoxTreeItem<>();
                checkBoxTreeItem11.setValue(baseView.getName() != null ? baseView.getName() : name.replace(groupName, ""));
                checkBoxTreeItem11.setMapName(name);
                checkBoxTreeItem11.setTag(baseView);
                checkBoxTreeItem11.setExpanded(true);
                checkBoxTreeItem11.setSelected(baseView.getVisibilityFX() && (baseView.getVisibility() == null || expressionUtils.parseExpr(baseView.getVisibility()) > 0.0d));
                if (isGroup) {
                    checkBoxTreeItem.getChildren().add(checkBoxTreeItem11);
                    checkBoxTreeItem.setLeftIcon(new Group());
                    checkBoxTreeItem11.setLeftIcon(baseView);
                } else {
                    groupMap = map;
                    treeItem.getChildren().add(checkBoxTreeItem11);
                    treeItem.setLeftIcon(new Lockscreen());
                    checkBoxTreeItem11.setLeftIcon(baseView);
                }
                checkBoxTreeItem.getJfxCheckBox().selectedProperty().addListener((observable, oldValue, newValue) -> {
                    Group mapGroup = (Group) groupMap.get(checkBoxTreeItem.getMapName());
                    mapGroup.setVisibilityFX(newValue);
                    mapGroup.getGroupViewMap().keySet().forEach(nameGroup -> {
                        mapGroup.getGroupViewMap().get(nameGroup).setVisibilityFX(newValue);
                        checkBoxTreeItem11.getJfxCheckBox().setSelected(newValue);
                    });
                    if (rightViewNodeMap.get(checkBoxTreeItem.getMapName()) != null) {
                        rightViewNodeMap.get(checkBoxTreeItem.getMapName()).setVisible(newValue);
                    }
                });
                checkBoxTreeItem11.getJfxCheckBox().selectedProperty().addListener((observable, oldValue, newValue) -> {
                    map.get(checkBoxTreeItem11.getMapName()).setVisibilityFX(newValue);
                    if (rightViewNodeMap.get(checkBoxTreeItem11.getMapName()) != null) {
                        rightViewNodeMap.get(checkBoxTreeItem11.getMapName()).setVisible(newValue);
                    }
                });
            }
        });
        if (isGroup) {
            treeItem.getChildren().add(checkBoxTreeItem);
        }
    }


    public void snapshot(Node view, Consumer<javafx.scene.image.Image> consumer) {
        Platform.runLater(() -> {
            SnapshotParameters snapshotParameters = new SnapshotParameters();
            snapshotParameters.setViewport(new Rectangle2D(0, 0, 480, 854));
            javafx.scene.image.Image image = view.snapshot(snapshotParameters, null);
            if (consumer != null) {
                consumer.accept(image);
            }
        });
    }

    private Node parseLockscreenView(BaseView baseView) {
        if (baseView instanceof com.thememaker.lockstyle.bean.ui.Image) {
            com.thememaker.lockstyle.bean.ui.Image image = (com.thememaker.lockstyle.bean.ui.Image) baseView;
            if (image.getX() != null && image.getY() != null) {
                //解锁标识
                if (image.getX().contains("#unlocker.move_x") || image.getY().contains("#unlocker.move_y")) {
                    image.setUnlockMoveFX(true);
                }
                //适配标识
                if (baseView.getY().contains("#screen_height-1920+")) {
                    baseView.setY(baseView.getY().replace("#screen_height-1920+", ""));
                    baseView.setFitFX(true);
                }
            }
            ImageView imageView;
            Button button = new Button();
            button.setPadding(new Insets(0));
            Path path = LockscreenViewPaesiiUtils.getInstance(expressionUtils).paesiiImagePath(image, lockscreenPathString);
            imageView = initImageView(button, expressionUtils.parseExpr(baseView.getX()), expressionUtils.parseExpr(baseView.getY()), path == null ? null : path.toString(), baseView.getFitFX());
            double pivotX = 0, pivotY = 0, rotation = 0;
            if (image.getPointX() != null) {
                pivotX = expressionUtils.parseExpr(image.getPointX());
            }
            if (image.getPointY() != null) {
                pivotY = expressionUtils.parseExpr(image.getPointY());
            }
            if (image.getRotation() != null) {
                rotation = expressionUtils.parseExpr(image.getRotation());
            }
            if (image.getAlpha() != null) {
                imageView.setStyle("-fx-opacity:" + expressionUtils.parseExpr(image.getAlpha()) / 255 + ";");
            }
            if (image.getVisibility() != null) {
                if (expressionUtils.parseExpr(image.getVisibility()) >= 1) {
                    imageView.setVisible(true);
                } else {
                    imageView.setVisible(false);
                }
            }
            imageView.getTransforms().add(new Rotate(rotation, pivotX, pivotY));
            if ("center".equals(image.getAlign())) {
                imageView.setLayoutX(imageView.getLayoutX() - imageView.getFitWidth() / 2);
                button.setLayoutX(button.getLayoutX() - button.getPrefWidth() / 2);
            }
            if ("center".equals(image.getAlignV())) {
                imageView.setLayoutY(imageView.getLayoutY() - imageView.getFitHeight() / 2);
                button.setLayoutY(button.getLayoutY() - button.getPrefHeight() / 2);
            }
            button.setStyle("-fx-border-color: transparent;-fx-background-color: transparent;");
            button.setGraphic(imageView);
            if (baseView.getVisibilityFX() != null && baseView.getVisibilityFX()) {
                button.setVisible(true);
            } else {
                button.setVisible(false);
            }
            if (!isEdit) {
                lockstyleShowRightEventControl.initAnimation(image, imageView, o -> {
                    parallelTransitionList.add(o);
                });
            } else {
                if (baseView.getName() == null) {
                    lockstyleShowRightEventControl.initButtonEvent(baseView, button, null);
                } else {
                    if (!baseView.getName().equals("bg")) {
                        lockstyleShowRightEventControl.initButtonEvent(baseView, button, null);
                    } else {
                        return imageView;
                    }
                }
            }
            return button;
        } else if (baseView instanceof Var) {
            expressionUtils.addVariable(baseView.getName(), expressionUtils.parseExpr(((Var) baseView).getExpression()));
        } else if (baseView instanceof Group) {
            Node node = parseGroupView((Group) baseView);
            return node;
        } else if (baseView instanceof Wallpaper) {
            Wallpaper wallpaper = (Wallpaper) baseView;
            ImageView imageView;
            Button button = new Button();
            button.setPadding(new Insets(0));
            Path path = null;
            if (wallpaper.getSrc() != null) {
                path = Paths.get(lockscreenPathString, wallpaper.getSrc());
                if (wallpaper.getSrcid() != null) {
                    path = Paths.get(path.toString()
                            .replace(".png", "_" + (int) expressionUtils.parseExpr(wallpaper.getSrcid()) + ".png")
                            .replace(".jpg", "_" + (int) expressionUtils.parseExpr(wallpaper.getSrcid()) + ".jpg"));
                }
            } else {
                path = Paths.get(lockscreenPathString, "default_lock_wallpaper.jpg");
                baseView.setX("0");
                baseView.setY("0");
            }
            imageView = initImageView(button, expressionUtils.parseExpr(baseView.getX()), expressionUtils.parseExpr(baseView.getY()), path == null ? null : path.toString(), baseView.getFitFX());
            if ("center".equals(wallpaper.getAlign())) {
                imageView.setLayoutX(imageView.getLayoutX() - imageView.getFitWidth() / 2);
                button.setLayoutX(button.getLayoutX() - button.getPrefWidth() / 2);
            }
            if ("center".equals(wallpaper.getAlignV())) {
                imageView.setLayoutY(imageView.getLayoutY() - imageView.getFitHeight() / 2);
                button.setLayoutY(button.getLayoutY() - button.getPrefHeight() / 2);
            }
            button.setStyle("-fx-border-color: transparent;-fx-background-color: transparent");
            button.setGraphic(imageView);
            return button;
        } else if (baseView instanceof Text) {
            System.err.println("Text----------------------");
            Text text = (Text) baseView;
            Button button = initButton(baseView);
            double textSize = 12;
            if (!Strings.isNullOrEmpty(text.getSize())) {
                textSize = expressionUtils.parseExpr(text.getSize()) * rate * 0.8;
            }
            button.setTextAlignment(TextAlignment.LEFT);
            button.setAlignment(Pos.CENTER_LEFT);
            button.setFont(new Font(textSize));
            String textString = parseTextString(text);
            button.setText(textString);
            if (!Strings.isNullOrEmpty(text.getAlign())) {
                if (text.getAlign().equals("center")) {
                    button.setTextAlignment(TextAlignment.CENTER);
                    button.setAlignment(Pos.CENTER);
                    if (button.getPrefWidth() > 0) {
                        button.setLayoutX(button.getLayoutX() - button.getPrefWidth() / 2);
                    } else {
                        button.setLayoutX(button.getLayoutX() - textString.length() * textSize / 2);
                    }
                } else if (text.getAlign().equals("right")) {
                    button.setTextAlignment(TextAlignment.RIGHT);
                    button.setAlignment(Pos.CENTER_RIGHT);
                }
            }
            if (!Strings.isNullOrEmpty(text.getAlignV())) {
                if (text.getAlignV().equals("center")) {
                    if (button.getPrefHeight() > 0) {
                        button.setLayoutY(button.getLayoutY() - button.getPrefHeight() / 2);
                    } else {
                        button.setLayoutY(button.getLayoutY() - textSize / 2);
                    }
                }
            }
            if (!Strings.isNullOrEmpty(text.getColor())) {
                button.setStyle(button.getStyle() + "-fx-text-fill: " + text.getColor() + ";");
            } else {
                button.setStyle(button.getStyle() + "-fx-text-fill: #000000;");
            }
            if (isEdit) {
                String baseStyle = button.getStyle();
                button.setStyle(baseStyle + "-fx-border-color: transparent;-fx-background-color: transparent");
                lockstyleShowRightEventControl.initButtonEvent(baseView, button, baseStyle);
            }
            return button;
        } else if (baseView instanceof com.thememaker.lockstyle.bean.ui.Slider) {

        } else if (baseView instanceof com.thememaker.lockstyle.bean.ui.Button) {
            System.out.println("Button >>> " + JSONObject.toJSON(baseView));
            Button button = initButton(baseView);
            button.setStyle("-fx-border-color: transparent;-fx-background-color: transparent;");
            if (isEdit) {
                lockstyleShowRightEventControl.initButtonEvent(baseView, button, null);
            } else {
                lockstyleShowRightEventControl.initButtonClickEvent(baseView, button, groupMap, o -> {
                    lockscreen.setLockScreenViewMap(o);
                });
            }
            if (((com.thememaker.lockstyle.bean.ui.Button) baseView).getAlign() != null || ((com.thememaker.lockstyle.bean.ui.Button) baseView).getAlignV() != null) {
                ErrorLogUtils.getInstance().createLog(themeFileInfo, "Button不允许align alignV存在 " + JSONObject.toJSON(baseView));
            }
            if (((com.thememaker.lockstyle.bean.ui.Button) baseView).getNormal() != null) {
                return parseButtonView((com.thememaker.lockstyle.bean.ui.Button) baseView, button);
            } else {
                return button;
            }
        }
        return null;
    }

    private String parseTextString(Text text) {
        String textString = text.getText();
        if (!Strings.isNullOrEmpty(text.getFormat()) && !Strings.isNullOrEmpty(text.getParas())) {
            String parasString = text.getParas();
            String[] args = parasString.split(",");
            Object[] object = new Object[args.length];
            for (int i = 0; i < args.length; i++) {
                if (args[i].startsWith("@")) {
                    if (args[i].contains("city")) {
                        object[i] = "北京";
                    } else if (args[i].contains("weather_temperature")) {
                        object[i] = "22℃";
                    } else if (args[i].contains("weather_description")) {
                        object[i] = "多云";
                    } else {
                        object[i] = "String";
                    }
                } else {
                    object[i] = (int) expressionUtils.parseExpr(args[i]);
                }
            }
            textString = String.format(text.getFormat(), object);
        }
        if (!Strings.isNullOrEmpty(text.getTextExp())) {
            String[] textExps = text.getTextExp().split("\\+");
            StringBuffer sb = new StringBuffer();
            for (String textExp : textExps) {
                if (textExp.contains("'")) {
                    sb.append(textExp.replace("'", ""));
                } else {
                    sb.append(expressionUtils.parseExpr(textExp.trim()) + "");
                }
            }
            textString = sb.toString();
        }
        return textString;
    }

    private Button initButton(BaseView baseView) {
        Button button = new Button();
        button.setLayoutX(expressionUtils.parseExpr(baseView.getX()) * rate);
        button.setLayoutY(expressionUtils.parseExpr(baseView.getY()) * rate);
        if (!Strings.isNullOrEmpty(baseView.getW())) {
            button.setPrefWidth(expressionUtils.parseExpr(baseView.getW()) * rate);
        }
        if (!Strings.isNullOrEmpty(baseView.getH())) {
            button.setPrefHeight(expressionUtils.parseExpr(baseView.getH()) * rate);
        }
        if (!Strings.isNullOrEmpty(baseView.getAlpha())) {
            button.setStyle("-fx-opacity:" + expressionUtils.parseExpr(baseView.getAlpha()) / 255 + ";");
        }
        if (baseView.getVisibilityFX() != null && baseView.getVisibilityFX()) {
            if (!Strings.isNullOrEmpty(baseView.getVisibility())) {
                button.setVisible(expressionUtils.parseExpr(baseView.getVisibility()) >= 1);
            }
        } else {
            button.setVisible(false);
        }
        return button;
    }

    private ImageView initImageView(Button button, double x, double y, String path, Boolean fitFX) {
        boolean fit = Optional.ofNullable(fitFX).orElse(false);
        javafx.scene.image.Image image = new javafx.scene.image.Image(Paths.get(path).toUri().toString());
        double width = image.getWidth();
        double height = image.getHeight();
        ImageView imageView = new ImageView(image);
        imageView.setFitWidth(width * rate);
        imageView.setFitHeight(height * rate);
        imageView.setLayoutX(x * rate);
        if (fit) {
            imageView.setLayoutY((LayoutComponentUtils.screen_heigth - 1920 + y) * rate);
        } else {
            imageView.setLayoutY(y * rate);
        }
        if (button != null) {
            button.setPrefWidth(width * rate);
            button.setPrefHeight(height * rate);
            button.setLayoutX(x * rate);
            if (fit) {
                button.setLayoutY((LayoutComponentUtils.screen_heigth - 1920 + y) * rate);
            } else {
                button.setLayoutY(y * rate);
            }
        }
        return imageView;
    }

    public void updateRightPreview() {
        parseLinkedView(lockscreen.getLockScreenViewMap());
    }

    public void updateRightPreview(BaseView baseView) {
        lockscreen.getLockScreenViewMap().put(baseView.getId(), baseView);
        if (rightViewNodeMap.get(baseView.getId()) != null) {
            int index = centerAnchorPane.getChildren().indexOf(rightViewNodeMap.get(baseView.getId()));
            if (index >= 0) {
                Node node = parseLockscreenView(baseView);
                centerAnchorPane.getChildren().set(index, node);
                rightViewNodeMap.put(baseView.getId(), node);
            } else {
                parseLinkedView(lockscreen.getLockScreenViewMap());
            }
        } else {
            parseLinkedView(lockscreen.getLockScreenViewMap());
        }
    }

    public void leftModelSwitch(Node node, VBox pane) {
        VBox vBox = new VBox();
        vBox.setPrefWidth(250);
        HBox trigger = new HBox();

        trigger.setStyle("-fx-background-color: #F1F1F1");
        MenuBar menuBar = new MenuBar();
        menuBar.setPadding(new Insets(0, 0, 0, 20));
        Menu menu1 = new Menu();
        menuBar.getMenus().add(menu1);
        if (LayoutComponentUtils.patternID == 1) {
            menu1.setText("标准模式");
            menu1.setGraphic(SVGLoadUtils.getInstance().getGroupXMLSVG(15, buttonColor));
        } else if (LayoutComponentUtils.patternID == 2) {
            menu1.setText("高级模式");
            menu1.setGraphic(SVGLoadUtils.getInstance().getSliderXMLSVG(15, buttonColor));
        }

        MenuItem menu121 = new MenuItem("标准模式");
        menu121.setGraphic(SVGLoadUtils.getInstance().getGroupXMLSVG(15, buttonColor));
        MenuItem menu122 = new MenuItem("高级模式");
        menu122.setGraphic(SVGLoadUtils.getInstance().getSliderXMLSVG(15, buttonColor));
        menu1.getItems().add(menu121);
        menu1.getItems().add(menu122);
        menu121.setStyle("-fx-padding");
        menuBar.setStyle("-fx-font-size: 15");
        vBox.getChildren().add(menuBar);
        trigger.setPadding(new Insets(5, 2, 5, 50));


        JFXButton button = new JFXButton("新增组件");
        button.setGraphic(SVGLoadUtils.getInstance().getAddSVG(15, Color.WHITE));
        button.setPrefSize(120, 30);
        vBox.setStyle("-fx-background-color: #ffffff");
        button.setStyle("-fx-text-fill:WHITE;-fx-background-color:#716A94;-fx-font-size:14px;");

        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                new CreateControlDialog(stage, lockscreenPath, expressionUtils, baseView -> {
                    baseView.setId("lockscreen_add_" + count);
                    lockscreen.getLockScreenViewMap().put("lockscreen_add_" + count, baseView);
                    count++;
                    parseLinkedView(lockscreen.getLockScreenViewMap());
                    leftAnchorPane.getChildren().clear();
                    leftModelSwitch(parseListView(lockscreen.getLockScreenViewMap()), leftAnchorPane);
                }).showDialog();
            }
        });

        if (LayoutComponentUtils.patternID == 1) {
            lockStyleCenterEditUtils.clear();
            lockstyleMainController.getCenterSplitPane().setDividerPosition(0, 1);
            menu1.setText("标准模式");
            menu1.setGraphic(SVGLoadUtils.getInstance().getGroupXMLSVG(15, buttonColor));
            trigger.getChildren().add(button);
            vBox.getChildren().add(trigger);

        } else if (LayoutComponentUtils.patternID == 2) {
            lockstyleMainController.getCenterSplitPane().setDividerPosition(0, 0.65);
            menu1.setText("高级模式");
            menu1.setGraphic(SVGLoadUtils.getInstance().getSliderXMLSVG(15, buttonColor));
        }

        vBox.getChildren().add(node);

        menu121.setOnAction((ActionEvent t) -> {
            if (LayoutComponentUtils.patternID == 2) {
                menu1.setText(menu121.getText());
                menu1.setGraphic(SVGLoadUtils.getInstance().getGroupXMLSVG(15, buttonColor));
                LayoutComponentUtils.patternID = 1;
                showLockscreen();
            }
        });
        menu122.setOnAction((ActionEvent t) -> {
            if (LayoutComponentUtils.patternID == 1) {
                menu1.setText(menu122.getText());
                menu1.setGraphic(SVGLoadUtils.getInstance().getSliderXMLSVG(15, buttonColor));
                LayoutComponentUtils.patternID = 2;
                showLockscreen();
            }
        });
        pane.getChildren().addAll(vBox);
    }

    private Parent parseListView(LinkedHashMap<String, BaseView> map) {
        final int[] groupNum = {1};//Group编号
        final int[] imageNum = {1};//Image编号
        final int[] sliderNum = {1};//Slider编号
        final int[] buttonNum = {1};//Button编号
        JFXListView<HBox> leftList = new JFXListView<HBox>();
        leftList.setId("");
        leftList.setPrefWidth(220);
        leftList.setPrefHeight(850);
        leftList.setMinHeight(850);
        leftList.setMaxHeight(850);
        leftList.getStyleClass().addAll("custom-jfx-list-view1");
        leftList.depthProperty().setValue(0);
        leftList.expandedProperty().set(true);
        leftList.setExpanded(false);
        leftList.setVerticalGap(10.0);
        ObservableList<HBox> themeTypeObservableList = FXCollections.observableArrayList();
        LinkedHashMap<String, BaseView> baseViewMap = baseModuleMap(map);
        themeTypeObservableList.add(getLeftContrlItem("壁纸", SVGLoadUtils.getInstance().getImageSVG(16, buttonColor), null));
        themeTypeObservableList.add(getLeftContrlItem("时间", SVGLoadUtils.getInstance().getTimeXMLSVG(16, buttonColor), null));
        themeTypeObservableList.add(getLeftContrlItem("解锁", SVGLoadUtils.getInstance().getUnlockerXMLSVG(16, buttonColor), null));
        map.keySet().forEach(name -> {
            BaseView baseView = map.get(name);
            if (baseView instanceof Group) {
                if (baseView.getName() != null) {
                    if (!baseView.getName().equals("time") && !baseView.getName().equals("time_grp")) {
                        newBaseViewMap(themeTypeObservableList, baseView.getName(), SVGLoadUtils.getInstance().getGroupXMLSVG(16, buttonColor), baseView, baseViewMap);
                    }
                } else {
                    newBaseViewMap(themeTypeObservableList, "组件_" + groupNum[0], SVGLoadUtils.getInstance().getGroupXMLSVG(16, buttonColor), baseView, baseViewMap);
                    groupNum[0] = groupNum[0] + 1;
                }
            } else if (baseView instanceof com.thememaker.lockstyle.bean.ui.Image) {
                if (baseView.getName() != null) {
                    if (!baseView.getName().equals("bg")) {
                        newBaseViewMap(themeTypeObservableList, baseView.getName(), SVGLoadUtils.getInstance().getImageSVG(16, buttonColor), baseView, baseViewMap);
                    }
                } else {
                    newBaseViewMap(themeTypeObservableList, "图片_" + imageNum[0], SVGLoadUtils.getInstance().getImageSVG(16, buttonColor), baseView, baseViewMap);
                    imageNum[0] = imageNum[0] + 1;
                }
            } else if (baseView instanceof com.thememaker.lockstyle.bean.ui.Slider || baseView instanceof Unlocker) {
                if (baseView.getName() != null) {
                    if (!baseView.getName().equals("unlocker")) {
                        newBaseViewMap(themeTypeObservableList, baseView.getName(), SVGLoadUtils.getInstance().getSliderXMLSVG(16, buttonColor), baseView, baseViewMap);
                    }
                } else {
                    newBaseViewMap(themeTypeObservableList, "滑块_" + sliderNum[0], SVGLoadUtils.getInstance().getSliderXMLSVG(16, buttonColor), baseView, baseViewMap);
                    sliderNum[0] = sliderNum[0] + 1;
                }
            } else if (baseView instanceof Wallpaper) {
            } else if (baseView instanceof com.thememaker.lockstyle.bean.ui.Button) {
                if (baseView.getName() != null) {
                    newBaseViewMap(themeTypeObservableList, baseView.getName(), SVGLoadUtils.getInstance().getButtonXMLSVG(16, buttonColor), baseView, baseViewMap);
                } else {
                    newBaseViewMap(themeTypeObservableList, "按钮_" + buttonNum[0], SVGLoadUtils.getInstance().getButtonXMLSVG(16, buttonColor), baseView, baseViewMap);
                    buttonNum[0] = buttonNum[0] + 1;
                }
            }
        });
        leftList.setItems(themeTypeObservableList);
        leftList.getSelectionModel().select(0);
        if (baseViewMap.get("壁纸") != null) {
            lockstyleControlUtils.showControl(baseViewMap.get("壁纸"), this::updateRightPreview);
        } else {
            lockstyleControlUtils.showControl(getControlName("壁纸"), this::updateRightPreview);
        }
        leftList.getSelectionModel().selectedItemProperty().addListener(
                (ObservableValue<? extends HBox> observable, HBox oldValue, HBox newValue) -> {
                    Label label = (Label) newValue.getChildren().get(1);
                    BaseView baseView = baseViewMap.get(label.getText());
                    if (baseView != null) {
                        lockstyleControlUtils.showControl(baseView, this::updateRightPreview);
                    } else {
                        lockstyleControlUtils.showControl(getControlName(label.getText()), baseView1 -> {
                            if (label.getText().equals("壁纸")) {
                                LinkedHashMap<String, BaseView> linkedHashMap = new LinkedHashMap<>();
                                linkedHashMap.put("lockscreen_add_" + count, baseView1);
                                linkedHashMap.putAll(lockscreen.getLockScreenViewMap());
                                lockscreen.setLockScreenViewMap(linkedHashMap);
                            } else {
                                baseView1.setId("lockscreen_add_" + count);
                                lockscreen.getLockScreenViewMap().put("lockscreen_add_" + count, baseView1);
                            }
                            baseViewMap.put(label.getText(), baseView1);
                            count++;
                            parseLinkedView(lockscreen.getLockScreenViewMap());
                        });
                    }
                });
        return leftList;
    }

    private String getControlName(String labelText) {
        String name = ImageControl.class.getSimpleName();
        switch (labelText) {
            case "壁纸":
                name = WallpaperControl.class.getSimpleName();
                break;
            case "时间":
                name = TimeGroupControl.class.getSimpleName();
                break;
            case "解锁":
                name = UnlockerControl.class.getSimpleName();
                break;
        }
        return name;
    }

    private LinkedHashMap<String, BaseView> baseModuleMap(LinkedHashMap<String, BaseView> map) {
        LinkedHashMap<String, BaseView> baseViewMap = new LinkedHashMap<>();
        BaseView[] baseViews = new BaseView[3];
        map.keySet().forEach(name -> {
            BaseView baseView = map.get(name);
            if (baseView.getName() != null) {
                if (baseView instanceof Group) {
                    if (baseView.getName().equals("time") || baseView.getName().equals("time_grp")) {
                        baseViews[1] = baseView;
                    }
                } else if (baseView instanceof Image) {
                    if (baseView.getName().equals("bg")) {
                        baseViews[0] = baseView;
                    }
                } else if (baseView instanceof Unlocker || baseView instanceof Slider) {
                    if (baseView.getName().equals("unlocker")) {
                        baseViews[2] = baseView;
                    }
                } else if (baseView instanceof Wallpaper) {
                    baseViews[0] = baseView;
                }
            }
        });
        System.out.println("baseViews[0]>>>>>>>>>" + baseViews[0]);

        System.out.println("时间" + baseViews[1]);
        baseViewMap.put("壁纸", baseViews[0]);
        baseViewMap.put("时间", baseViews[1]);
        baseViewMap.put("解锁", baseViews[2]);
        return baseViewMap;
    }

    private void newBaseViewMap(ObservableList<HBox> themeTypeObservableList, String name, SVGGlyph svgGlyph, BaseView baseView, LinkedHashMap<String, BaseView> baseViewMap) {
        if (baseView instanceof Image) {
            themeTypeObservableList.add(getLeftContrlItem(name, svgGlyph, baseView));
        } else {
            themeTypeObservableList.add(getLeftContrlItem(name, svgGlyph, null));
        }
        baseViewMap.put(name, baseView);
    }

    private HBox getLeftContrlItem(String name, SVGGlyph stackPane, BaseView baseView) {
        HBox hBoxLeft = new HBox();
//        hBoxLeft.setMaxSize(200, 30);
//        hBoxLeft.setPrefSize(200, 30);
//        hBoxLeft.setMinSize(200, 30);
        hBoxLeft.setPadding(new Insets(0, 10, 0, 10));
        hBoxLeft.setSpacing(15);
        hBoxLeft.setAlignment(Pos.CENTER_LEFT);
        Label label = new Label(name);
        label.setId("diy-fontColor");
        label.setFont(Font.font(16));
        label.setEllipsisString(name);

        label.setPrefSize(170, 30);
//        label.setMaxSize(230, 30);
//        label.setMinSize(230, 30);
        if (baseView != null && baseView instanceof Image) {
            ContextMenu contextMenu = new ContextMenu();
            MenuItem register = new MenuItem("删除");
            contextMenu.getItems().addAll(register);
            label.setContextMenu(contextMenu);
            register.setOnAction(event -> {
                lockscreen.getLockScreenViewMap().remove(baseView.getId());
                parseLinkedView(lockscreen.getLockScreenViewMap());
                leftAnchorPane.getChildren().clear();
                leftModelSwitch(parseListView(lockscreen.getLockScreenViewMap()), leftAnchorPane);
            });
        }
        hBoxLeft.getChildren().addAll(stackPane, label);
        return hBoxLeft;
    }
}
